package com.code.monitor.service.impl;

import com.code.monitor.conditions.MysqlRuntimeCondition;
import com.code.monitor.mapper.MachineInfoMapper;
import com.code.monitor.model.MachineInfo;
import com.code.monitor.service.MachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Conditional(MysqlRuntimeCondition.class)
@Service
public class MysqlMachineServiceImpl implements MachineService {
    @Autowired
    private MachineInfoMapper machineInfoMapper;

    @Override
    public void addMachineInfo(MachineInfo machineInfo) {
        machineInfoMapper.insert(machineInfo);
    }

    @Override
    public void delMachineInfo(String ip) {
        machineInfoMapper.deleteByIP(ip);
    }

    @Override
    public Collection<MachineInfo> queryAllMachine() {
        return machineInfoMapper.queryAll();
    }

    @Override
    public MachineInfo queryMachineByIP(String ip) {
        return machineInfoMapper.queryByIP(ip);
    }
}
